package com.ledim.widget.recyclerview.loadmore;

import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;
import com.ledim.widget.recyclerview.BaseViewHolder;
import com.letv.android.young.client.R;

/**
 * Created by ccx on 2016/12/05.
 * 乐次元Rv 上拉加载view
 */

public final class LedimLoadMoreView extends LoadMoreView {

    private AnimationDrawable mLoadAnimationDrawable = null;
    private ImageView mProgressBar;

    @Override
    public int getLayoutId() {
        return R.layout.ledim_recyclerview_loadmore;
    }

    @Override
    public void onLoading(BaseViewHolder holder) {
        holder.setVisible(R.id.tv_state, true);
        holder.setVisible(R.id.iv_progress, true);
        holder.setText(R.id.tv_state, R.string.loadmore_state_loading);
        if (mProgressBar == null) {
            mProgressBar = holder.getView(R.id.iv_progress);
            mProgressBar.setVisibility(View.VISIBLE);
            mProgressBar.setImageResource(R.anim.refresh_animation);
            mLoadAnimationDrawable = (AnimationDrawable) mProgressBar.getDrawable();
            mLoadAnimationDrawable.setOneShot(false);
        }
    }

    @Override
    public void onEnd(BaseViewHolder holder) {
        holder.setText(R.id.tv_state, R.string.loadmore_state_end);
        if (mProgressBar != null) {
            mProgressBar.setVisibility(View.GONE);
            mLoadAnimationDrawable.stop();
        }
    }

    @Override
    public void onFailed(BaseViewHolder holder) {
        holder.setText(R.id.tv_state, R.string.loadmore_state_failed);
        if (mProgressBar != null) {
            mProgressBar.setVisibility(View.GONE);
            mLoadAnimationDrawable.stop();
        }
    }

    @Override
    public void onNormal(BaseViewHolder holder) {
        holder.setVisible(R.id.tv_state, false);
        holder.setVisible(R.id.iv_progress, false);
        if (mLoadAnimationDrawable != null) {
            mLoadAnimationDrawable.stop();
        }
    }
}
